package com.yanqu.road.server.cmd.activity.snowgarden;

import com.yanqu.road.entity.activity.snowgarden.SnowGardenUserData;
import com.yanqu.road.entity.activity.snowgarden.config.SnowGardenConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SnowGardenProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.snowgarden.SnowGardenModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.snowgarden.SnowGardenMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_SNOW_GARDEN_GET_VISIT_LIST, desc = "请求冰雪游园会拜访数据")
public class SnowGardenGetVisitCmd extends AbstractCommand {
    private int page;        // 页数
    private int pageSize;    // 每页数据量

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        SnowGardenProto.SnowGardenVisitListReqMsg reqMsg = SnowGardenProto.SnowGardenVisitListReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        SnowGardenProto.SnowGardenVisitListReqMsg reqMsg = SnowGardenProto.SnowGardenVisitListReqMsg.parseFrom(packet.getBytes());
        if (reqMsg.getPage() > 1) {
            SnowGardenProto.SnowGardenVisitListRespMsg.Builder respMsg = SnowGardenProto.SnowGardenVisitListRespMsg.newBuilder();
            respMsg.setRet(0);
            respMsg.setPageSize(reqMsg.getPageSize());
            respMsg.setPage(reqMsg.getPage());
            player.sendPacket(ClientProtocol.U_SNOW_GARDEN_GET_VISITOR_LIST, respMsg);
            return;
        }
        ret = player.getModule(SnowGardenModule.class).getVisitList();
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            SnowGardenProto.SnowGardenVisitListRespMsg.Builder builder = SnowGardenProto.SnowGardenVisitListRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_SNOW_GARDEN_GET_VISITOR_LIST, builder);
        }
    }
}
